/**
* @file image_processor_v100.cpp
*
* Copyright (C) Huawei Technologies Co., Ltd. 2019-2020. All Rights Reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "video_processor_v100.h"
#include "common/log_inner.h"

namespace acl {
    namespace dvpp {
    namespace {
        constexpr uint32_t V100_CHANNEL_ID_CEILING = 31U;
        constexpr uint32_t V100_CHANNEL_ID_FLOOR = 0U;
    }

        /**
          * VDEC set channel id for channel desc.
          * @param channelDesc[in|out] channel desc
          * @param channelId[in] channel id
          * @return ACL_SUCCESS for ok, others for fail
          */
        aclError VideoProcessorV100::aclvdecSetChannelDescChannelId(aclvdecChannelDesc *const channelDesc,
                                                                    const uint32_t channelId) const
        {
            ACL_LOG_DEBUG("start to execute aclvdecSetChannelDescChannelId");
            if (channelDesc == nullptr) {
                ACL_LOG_ERROR("channelDesc is null.");
                const char_t *argList[] = {"param"};
                const char_t *argVal[] = {"channelDesc"};
                acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_NULL_POINTER_MSG, argList, argVal, 1U);
                return ACL_ERROR_INVALID_PARAM;
            }

            if (channelId > V100_CHANNEL_ID_CEILING) {
                ACL_LOG_ERROR("the value of channelId[%u] is invalid, it should be between in [%u, %u]",
                    channelId, V100_CHANNEL_ID_FLOOR, V100_CHANNEL_ID_CEILING);
                const char_t *argList[] = {"param"};
                const char_t *argVal[] = {"channelDesc"};
                acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_NULL_POINTER_MSG,
                    argList, argVal, 1U);
                return ACL_ERROR_INVALID_PARAM;
            }

            channelDesc->vdecDesc.channelId = channelId;
            return ACL_SUCCESS;
        }

        /**
          * VDEC set outPicFormat for channel desc.
          * @param channelDesc[in|out] channel desc
          * @param outPicFormat[in] outPicFormat
          * @return ACL_SUCCESS for ok, others for fail
          */
        aclError VideoProcessorV100::aclvdecSetChannelDescOutPicFormat(aclvdecChannelDesc *const channelDesc,
                                                                       const acldvppPixelFormat outPicFormat) const
        {
            ACL_LOG_DEBUG("start to execute aclvdecSetChannelDescOutPicFormat");
            if (channelDesc == nullptr) {
                ACL_LOG_ERROR("channelDesc is null.");
                const char_t *argList[] = {"param"};
                const char_t *argVal[] = {"channelDesc"};
                acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_NULL_POINTER_MSG,
                    argList, argVal, 1U);
                return ACL_ERROR_INVALID_PARAM;
            }
            // v100 only support 2 format
            if ((outPicFormat != PIXEL_FORMAT_YUV_SEMIPLANAR_420) &&
                (outPicFormat != PIXEL_FORMAT_YVU_SEMIPLANAR_420)) {
                ACL_LOG_ERROR("the current outPicFormat[%d] is not support in this version, only support "
                    "PIXEL_FORMAT_YUV_SEMIPLANAR_420 and PIXEL_FORMAT_YVU_SEMIPLANAR_420",
                    static_cast<int32_t>(outPicFormat));
                const std::string val = acl::AclErrorLogManager::FormatStr("the current outPicFormat[%d]",
                    static_cast<int32_t>(outPicFormat));
                const char_t *argList[] = {"feature", "reason"};
                const char_t *argVal[] = {"outPicFormat", val.c_str()};
                acl::AclErrorLogManager::ReportInputErrorWithChar(acl::UNSUPPORTED_FEATURE_MSG,
                    argList, argVal, 2U);
                return ACL_ERROR_INVALID_PARAM;
            }

            channelDesc->vdecDesc.outPicFormat = static_cast<uint32_t>(outPicFormat);
            return ACL_SUCCESS;
        }
    }
}
